// pages/question-detail/index.js
Page({

  /**
   * 页面的初始数据
   */
	data: {
		datas: "",
		datas_list: "",
		Q_ID: "",
		A_ID: "",
		A_IsCheck: "",
		A_Note: "",
		A_Score: "",
		A_Yintegral: "",
		AImage: "",
		Q_ID: "",
		U_ID: "",
		U_Nickname: "",
    tousuNote:"",
		myDialog: false,
	},

  /**
   * 生命周期函数--监听页面加载
   */
	onLoad: function (options) {
		console.log("sssffff");
		console.log(options);
		console.log(options.dataList);
		console.log(JSON.parse(options.dataList).A_ID);
		var _this = this;
		_this.setData({
			datas_list: JSON.parse(options.dataList),
      A_ID: JSON.parse(options.dataList).A_ID,
			A_IsCheck: JSON.parse(options.dataList).A_Note,
			A_Note: JSON.parse(options.dataList).A_Note,
			A_Score: JSON.parse(options.dataList).A_Score,
			A_Yintegral: JSON.parse(options.dataList).A_Yintegral,
			AImage: JSON.parse(options.dataList).AImage,
			Q_ID: JSON.parse(options.dataList).Q_ID,
			U_ID: JSON.parse(options.dataList).U_ID,
			U_Nickname: JSON.parse(options.dataList).U_Nickname,
		}),

			console.log("defen");
		console.log(_this.data.A_Score);
		console.log("defen");

		wx.request({
			url: "https://www.chnode.xyz/api/My.ashx?",
			data: {
				DataType: "MyQuestionDetail",
				Q_ID: _this.data.Q_ID,
			},
			success: function (res) {
				console.log("1111");
				console.log(res);
				console.log("11111");
				if (res.data.isok == "false")
					_this.showZanTopTips(res.data.info);
				else {
					_this.setData({
						datas: res.data.data
					})
					console.log(_this.data.datas)
				}
			}
		}),

			wx.request({
				url: "https://www.chnode.xyz/api/My.ashx?",
				data: {
					DataType: "My_Q_Answer",
					Q_ID: _this.data.Q_ID,
				},
				success: function (res) {
					console.log("vvvvvv");
					console.log(res.data.datas[0]);
					console.log("vvvvvv");

					if (res.data.isok == "false")
						_this.showZanTopTips(res.data.info);
					else {
						// _this.setData({
						//   datas_list: res.data.datas

						// })


					}
				}
			})

	},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
	onReady: function () {

	},

  /**
   * 生命周期函数--监听页面显示
   */
	onShow: function () {

	},

  /**
   * 生命周期函数--监听页面隐藏
   */
	onHide: function () {

	},

  /**
   * 生命周期函数--监听页面卸载
   */
	onUnload: function () {

	},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
	onPullDownRefresh: function () {

	},

  /**
   * 页面上拉触底事件的处理函数
   */
	onReachBottom: function () {

	},

  /**
   * 用户点击右上角分享
   */
	onShareAppMessage: function () {

	},

	addAddess: function () {
		console.log("click");//
		// wx.navigateTo({
		//   url: "/pages/address-add/index"
		// })
	},

	btnClicked_queren: function (e) {
		var _this = this;
		var temp_index_aid = e.target.dataset.index;
		console.log(temp_index_aid);
		console.log(_this.data.datas_list);
		console.log(_this.data.datas_list[temp_index_aid].A_ID);
		console.log(_this.data.Q_ID);
		wx.showModal({
			content: '确认答案后，将付给回答者相应的积分',
			success: function (res) {
				if (res.confirm) {
					console.log('是');


					var _Token;
					try {
						var value = wx.getStorageSync('Token')
						if (value) {
							// Do something with return value
							_Token = value
						}
					} catch (e) {
						// Do something when catch error
					}
					/////////

					wx.request({
						url: "https://www.chnode.xyz/api/My.ashx?",
						data: {
							DataType: "ConfirmAnswer",
							A_ID: _this.data.datas_list[temp_index_aid].A_ID,
							Q_UserToken: _Token,
							Q_ID: _this.data.Q_ID,
						},
						success: function (res) {
							console.log(res)
							if (res.data.isok == "false")
								_this.showZanTopTips(res.data.info);
							else {
								_this.setData({
									datas_list: res.data.datas
								})
								console.log(_this.data.datas)
							}
						}
					})
					/////////

				} else {
					console.log('否')
				}

			}
		})
	},

	btnClicked_pingjia: function (e) {
		console.log(e.target.dataset.index);
	},

	btnClicked_tousu: function (e) {
		this.setData({
			myDialog: true,
		})
	},
	btnClicked_tousu2: function (e) {
		this.setData({
			myDialog: false,
		})
	},

	fabu123: function (e) {
		console.log("tousu");
		var _this = this;

		var _Token;
		try {
			var value = wx.getStorageSync('Token')
			if (value) {
				// Do something with return value
				_Token = value
			}
		} catch (e) {
			// Do something when catch error
		}

		wx.request({
			url: "https://www.chnode.xyz/api/My.ashx?",
			data: {
				DataType: "ComplaintAnswer",
				Ingetral: _this.data.A_Score,
				A_ID: _this.data.A_ID,
        A_CompliantInfo: _this.data.tousuNote,
				A_IsAnonymity: "0",
				Q_UserToken: _Token
			},
			success: function (res) {
				console.log(res)
        wx.showModal({
          title: '提示',
          content: res.data.info,
          success: function (res) {
            if (res.confirm) {
              console.log('用户点击确定');
              wx.navigateBack({
                delta: 1
              })
            } else if (res.cancel) {
              console.log('用户点击取消')
            }
          }
        })  
				if (res.data.isok == "false") { }

				else {

				}
			}
		})
		/////////


	},

  bindButtonTap: function () {
    this.setData({
      focus: true
    })
    console.log("1111");
  },

  bindTextAreaBlur: function (e) {
    var _this = this;
    console.log("sssss");
    console.log(e.detail.value);
    console.log("sssssss")
    _this.setData({
      tousuNote: e.detail.value,
    })
    console.log(tousuNote);
  },
  bindFormSubmit: function (e) {
    console.log(e.detail.value.textarea)
  }

})